const conn = require('../../libs/DB/Conn');
const _ = require('underscore');
const actionList= {
    addDevice:"站点设备档案添加",
    delDevice:"站点设备档案删除",
    updateDevice:"站点设备档案修改",

    addDevicePatrolRecord:"增加巡检记录",
    addPatrolUser:"增加巡检人员",
    bindPatrolSite:"绑定巡检人员和站点",
    setSitePatrolCycle:"设置站点巡检周期",

    facilityAdd:"防洪资源设施档案增加",
    facilityDelete:"防洪资源设施档案删除",
    facilityUpdate:"防洪资源设施档案修改",
    facilityCoordinateSet:"防洪资源设施坐标添加",
    itemAdd:"防洪资源设施物资添加",
    itemUpdate:"防洪资源设施物资档案名称修改",
    itemDelete:"防洪资源设施物资删除",

    importDeviceFile:"导入站点设备列表",
    importFacilityItem:"导入物资仓库物资",

    addReservoir:"水库档案添加",
    delReservoir:"水库档案删除",
    updateReservoir:"水库档案修改",
    setReservoirThreshold:"水库阈值修改",

    addWaterResource:"水源地档案添加",
    delWaterResource:"水源地档案删除",
    updateWaterResource:"水源地档案修改",
    setWaterResourceThreshold:"水源地阈值修改",

    addRiver:"河道档案添加",
    delRiver:"河道档案删除",
    updateRiver:"河道档案修改",
    setRiverCoordinate:"河道坐标设置",
    setRiverPatrolCycle:"设置河道巡检周期",

    addRiverPatrolRecord:"增加河道巡检记录",
    bindPatrolRiver:"绑定巡检人员和河道",

    addSite:"站点档案添加",
    updateSite:"站点档案修改",
    delSite:"站点档案删除",
    setThreshold:"站点阈值设置",
    setSiteCoordinate:"设置站点坐标",

    reset:"重启设备",
    setIp:"设置IP",
    startUpload:"启动上传",
    systemStatus:"查看系统状态",

    userAdd:"用户档案添加",
    userDelete:"用户档案删除",
    userUpdate:"用户档案修改",
    resetPwd:"用户密码重置",
    updatePwd:"用户密码修改",

    userGroupAdd:"用户组档案添加",
    userGroupUpdate:"用户组档案修改",
    userGroupDelete:"用户组档案删除",
    setGroupAuth:"用户组权限设置",
    resetAdminMenu:"刷新用户组档案",

    addMapRiver:"地图河道档案添加",
    delMapRiver:"地图河道档案删除",
    updateMapRiver:"地图河道档案修改",
    setMapRiverCoordinate:"地图河道坐标设置",
}
module.exports = async function (params) {
    let userId = params.userId,
        actionType = params.actionType,
        actionName = actionList[actionType];
    let operationMsg = JSON.stringify(_.omit(params, 'user_id','actionType','ipAddress'));
    let insertObj = {user_id: userId, action_type: actionType,action_name:actionName,ip_address:params.ipAddress, operation_msg: operationMsg};
    let insertResult = await conn('INSERT INTO operation_record SET ?', [insertObj]);
    return {success: true, insertId: insertResult.insertId};
};
